﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using proRFID_DiemDanh.Chung;

namespace proRFID_DiemDanh.LichDay
{
    public partial class LichDay : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Load_Rpt_LichDay("", 0, 0, 0, 0,0);
                Load_DDL_GiaoVien();
            }
        }
        
        void Load_Rpt_LichDay(string NgayDay, int BuoiDay, int MaGV,int MaPhong,int MaMH,int MaLop)
        {
            DataTable dt = new DataTable();
            dt = mdLichDay.sp_LichDay_Select(NgayDay,BuoiDay,MaGV,MaPhong,MaMH,MaLop);
            Rpt_LichDay.DataSource = dt;
            Rpt_LichDay.DataBind();
        }

        protected void Imgcmd_Xem_Click(object sender, ImageClickEventArgs e)
        {
            DataTable dt = new DataTable();
            dt = mdLichDay.sp_LichDay_Select(txt_NgayHoc.Text, Convert.ToInt16(ddl_Buoi.SelectedValue), Convert.ToInt16(ddl_GiaoVien.SelectedValue), 0, 0, 0);
            Rpt_LichDay.DataSource = dt;
            Rpt_LichDay.DataBind();
        }
        void Load_DDL_GiaoVien()
        {
            DataTable dt = new DataTable();
            dt = mdLichDay.sp_GiaoVien_DDL(0);
            ddl_GiaoVien.DataSource = dt;
            ddl_GiaoVien.DataValueField = "MAGV";
            ddl_GiaoVien.DataTextField = "HOTENGV";
            ddl_GiaoVien.DataBind();
        }
        string Getmucchon()
        {
            if (string.IsNullOrEmpty(Request["xoa"]))
                return "";
            return Request["xoa"].ToString()+',';
        }
        void XoaMucChon()
        {
            string[] test = null;
            string[] test1 = null;
            string[] test2 = null;
            string date = "";
            string Mangchon = Getmucchon();
            test = Mangchon.ToString().Split(',');
            int count = 0;
            if (!string.IsNullOrEmpty(Mangchon))
            {
                for (int k = 0; k < test.Length - 1; k++)
                {
                    test1 = test[k].Split('@');
                    test2 = test1[0].Split('/');
                    date = "";
                    date = date + test2[2] + "-" + test2[1] + "-" + test2[0];


                    DataTable dt = new DataTable();
                    dt = mdLichDay.sp_LichDay_Delete(date, Convert.ToInt16(test1[1]), Convert.ToInt16(test1[2]), Convert.ToInt16(test1[3]), Convert.ToInt16(test1[4]), Convert.ToInt16(test1[5]));
                    if (dt.Rows[0]["ErrCode"].ToString() == "0")
                        count++;
                }
            }
            if (count > 0)
            {
                mdMain.OKBox(this, "Bạn đã xóa " + count + " dòng dữ liệu.", "/LichDay/LichDay.aspx");
            }
            else
            {
                mdMain.OKBox(this, "Xóa dữ liệu thất bại.", "/LichDay/LichDay.aspx");
            }
            
         
        }
        protected void cmd_xoa_Click(object sender, ImageClickEventArgs e)
        {
            XoaMucChon();
        }

    }
}